<template>
  <div class="loginCont">
    <video muted autoplay loop src="/video/logoVideo.mp4"></video>
    <div class="formMask">
      <div class="maskTop">
        <h1>码客直通车——后台管理系统</h1>
        <h3>Programmer through train - background management system</h3>
      </div>
      <div class="formCont">
        <div class="formLogo">
          <img src="/img/logo_b.png" />
        </div>
        <div class="formEnter">
          <div class="inputCont">
            <div class="inputName">Phone(手机号)</div>
            <div class="inputVal">
              <el-input
                v-model="account"
                type="text"
                size="large"
                placeholder="Enter your Phone"
              ></el-input>
            </div>
          </div>
          <div class="inputCont">
            <div class="inputName">Password(密码)</div>
            <div class="inputVal">
              <el-input
                v-model="password"
                type="password"
                size="large"
                placeholder="Enter your password"
              ></el-input>
            </div>
          </div>
          <!-- <btn style="width: 100%" value="登录" @click="loginFn"></btn> -->
          <div class="loginBtn" @click="loginFn">登录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import btn from "@/components/public/btn.vue";
import { login } from "@/http/api";
import { ElMessage } from "element-plus";

export default {
  components: { btn },
  data() {
    return {
      account: "",
      password: "",
    };
  },
  props: {},
  methods: {
    loginFn() {
      if (this.account == "") {
        ElMessage({
          message: "请输入手机号",
          type: "warning",
        });
        return false;
      } else if (this.password == "") {
        ElMessage({
          message: "请输入密码",
          type: "warning",
        });
        return false;
      }
      var data = {
        admin_username: this.account,
        admin_password: this.password,
      };
      login(data)
        .then((res) => {
          if (res.data.code == 1) {
            localStorage.setItem("token", res.data.data);
            localStorage.setItem("real_name", this.account);
            ElMessage({
              message: "登陆成功",
              type: "success",
            });
            setTimeout(() => {
              this.$router.push({ path: "/homeUser" });
            }, 1500);
          } else {
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage("服务器请求超时");
        });
    },
  },
  mounted() {},
  created() {},
};
</script>

<style scoped lang="less">
.loginCont {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
  video {
    width: 100%;
  }
  .formMask {
    width: 100%;
    position: absolute;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    left: 0;
    top: 0;
    .maskTop {
      text-align: center;
      margin-top: 70px;
      color: white;
      margin-bottom: 100px;
    }
    .formCont {
      background-color: #fff;
      width: 550px;
      margin: 0 auto;
      padding: 0 50px 30px;
      box-sizing: border-box;
      border-radius: 10px;
      .formLogo {
        width: 160px;
        height: 160px;
        border-radius: 50%;
        background-color: #fff;
        padding: 25px;
        box-sizing: border-box;
        position: relative;
        top: -60px;
        margin: 0 auto;
        overflow: hidden;
        img {
          width: 100%;
          border-radius: 50%;
        }
      }
      .formEnter {
        margin-top: -40px;
        .inputCont {
          width: 100%;
          margin-bottom: 25px;
          .inputName {
            margin-bottom: 10px;
          }
          .inputVal {
            display: flex;
            .phoneInput {
              width: 50px;
              flex: 1;
            }
          }
        }
        .loginBtn {
          padding: 0px 35px;
          background-color: #86a9fb;
          color: white;
          height: 40px;
          box-sizing: border-box;
          line-height: 40px;
          text-align: center;
          border-radius: 4px;
          cursor: pointer;
          transition: all 0.2s;
          font-size: 12px;
          width: 100%;
        }
        .loginBtn:hover {
          opacity: 0.8;
        }
      }
    }
  }
}
</style>
